package cn.tedu.ivos.vehicleRepair.service.impl;

import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicleRepair.mapper.VehiceRepairMapper;
import cn.tedu.ivos.vehicleRepair.pojo.dto.VehicleRepairParam;
import cn.tedu.ivos.vehicleRepair.pojo.dto.VehicleRepairquery;
import cn.tedu.ivos.vehicleRepair.pojo.entity.VehicleRepair;
import cn.tedu.ivos.vehicleRepair.pojo.vo.VehicleRepairVO;
import cn.tedu.ivos.vehicleRepair.service.VehicleRepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class VehicleRepairServiceImpl implements VehicleRepairService {

    @Autowired
    private VehiceRepairMapper vehiceRepairMapper;
    @Override
    public void saveVehicleRepair(VehicleRepairParam vehicleRepairParam) {
        VehicleRepair vehicleRepair = new VehicleRepair();
        BeanUtils.copyProperties(vehicleRepairParam, vehicleRepair);
        // 把VehicleId封装到VehicleRepairquery中进行查询
        VehicleRepairquery vehicleRepairquery = new VehicleRepairquery();
        vehicleRepairquery.setVehicleId(vehicleRepair.getVehicleId());
        if (vehicleRepair.getId() == null){
            vehicleRepair.setCreateTime(new Date());
            vehiceRepairMapper.insert(vehicleRepair);
        }else{
            //如果数据冲突则进行update操作
            vehicleRepair.setUpdateTime(new Date());
            vehiceRepairMapper.update(vehicleRepair);
        }
    }

    @Override
    public List<VehicleRepairVO> selectVehicleRepair(VehicleRepairquery vehicleQuery) {
        return vehiceRepairMapper.select(vehicleQuery);
    }

    @Override
    public void delete(Long id) {
        vehiceRepairMapper.delete(id);
    }


}
